package vnc.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ARPbit extends JPanel{

	public String[] names;
	public Object[] values;
	
	Point LocationBox = new Point(0,0);
	Dimension PaneSize = new Dimension(600,150); 
	JLabel jl=new JLabel();
	
	JButton HardwareType;
	JButton ProtocolType;
	JButton HardwareAddressLength;
	JButton ProtocolAddressLength;
	JButton Operation;
	JButton SenderHardwareAddress;
	JButton SenderProtocolAddress;
	JButton TargetHardwareAddress;
	JButton TargetProtocolAddress;
	
	
	public ARPbit(){
	
		HardwareType = new JButton("Hardware Type");
		ProtocolType = new JButton("Protocol Type");
		HardwareAddressLength = new JButton("Hardware Address Length");
		ProtocolAddressLength = new JButton("Protocol Address Length");
		Operation = new JButton("Operation");
		SenderHardwareAddress = new JButton("Sender Hardware Address");
		SenderProtocolAddress = new JButton("Sender Protocol Address");
		TargetHardwareAddress = new JButton("Target Hardware Address");
		TargetProtocolAddress = new JButton("Target Protocol Address");


		this.setLayout(null);
		this.setBackground(Color.white);

		
		
		this.removeBoxBorder(HardwareType);
		this.removeBoxBorder(ProtocolType);
		this.removeBoxBorder(HardwareAddressLength);
		this.removeBoxBorder(ProtocolAddressLength);
		this.removeBoxBorder(Operation);
		this.removeBoxBorder(SenderHardwareAddress);
		this.removeBoxBorder(SenderProtocolAddress);
		this.removeBoxBorder(TargetHardwareAddress);
		this.removeBoxBorder(TargetProtocolAddress);

		HardwareType.setBackground(new Color(0x8b,0x45,0x13));
		ProtocolType.setBackground(new Color(0x8b,0x45,0x13));
		
		HardwareAddressLength.setBackground(new Color(0x8b,0x59,0x27));
		ProtocolAddressLength.setBackground(new Color(0x8b,0x59,0x27));
		Operation.setBackground(new Color(0x8b,0x59,0x27));
		
		SenderHardwareAddress.setBackground(new Color(0x90,0x6d,0x3b));
		SenderProtocolAddress.setBackground(new Color(0x9a,0x77,0x45));
		TargetHardwareAddress.setBackground(new Color(0xa4,0x81,0x4f));
		TargetProtocolAddress.setBackground(new Color(0xae,0x8b,0x59));
		
		this.add(HardwareType);
		this.add(ProtocolType);
		this.add(HardwareAddressLength);
		this.add(ProtocolAddressLength);
		this.add(Operation);
		this.add(SenderHardwareAddress);
		this.add(SenderProtocolAddress);
		this.add(TargetHardwareAddress);
		this.add(TargetProtocolAddress);
		
		jl.setBounds(0, 160, 600, 120);
		this.add(jl);
	}
	public static void removeBoxBorder(JButton box){
		box.setBorderPainted(true);
		box.setContentAreaFilled(true);
		box.setDefaultCapable(false);
		box.setFocusPainted(false);
	}

	
	public void getInfos(final String[] names, final Object[] values) {
		
		this.names = names;
		this.values = values;
		Font f = new Font("",Font.BOLD,13);
		jl.setFont(f);
		
		HardwareType.setBounds(LocationBox.x, LocationBox.y,PaneSize.width/2, PaneSize.height/6);
		HardwareType.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				
				jl.setText((names[0]+" : "+values[0]));
			}
		});
		
		ProtocolType.setBounds(LocationBox.x + HardwareType.getWidth(), LocationBox.y,PaneSize.width/2, PaneSize.height/6);
		ProtocolType.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[1]+" : "+values[1]);
			}
		});
		HardwareAddressLength.setBounds(LocationBox.x, LocationBox.y+ProtocolType.getHeight(),PaneSize.width/4, PaneSize.height/6);
		HardwareAddressLength.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[2]+" : "+values[2]);
			}
		});
		
		ProtocolAddressLength.setBounds(LocationBox.x+HardwareAddressLength.getWidth(),LocationBox.y+ProtocolType.getHeight(),PaneSize.width/4, PaneSize.height/6);
		ProtocolAddressLength.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[3]+" : "+values[3]);
			}
		});
		
		Operation.setBounds(ProtocolAddressLength.getX()+ProtocolAddressLength.getWidth(), LocationBox.y+ProtocolType.getHeight(),PaneSize.width/2, PaneSize.height/6);
		Operation.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[4]+" : "+values[4]);
			}
		});
		
		
		SenderHardwareAddress.setBounds(LocationBox.x,Operation.getY()+Operation.getHeight(),PaneSize.width, PaneSize.height/6);
		SenderHardwareAddress.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[5]+" : "+values[5]);
			}
		});
		
		SenderProtocolAddress.setBounds(LocationBox.x, SenderHardwareAddress.getY()+SenderHardwareAddress.getHeight(),PaneSize.width, PaneSize.height/6);
		SenderProtocolAddress.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[6]+" : "+values[6]);
			}
		});
		
		TargetHardwareAddress.setBounds(LocationBox.x, SenderProtocolAddress.getY()+SenderProtocolAddress.getHeight(),PaneSize.width, PaneSize.height/6);
		TargetHardwareAddress.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[7]+" : "+values[7]);
			}
		});
		
		TargetProtocolAddress.setBounds(LocationBox.x, TargetHardwareAddress.getY()+TargetHardwareAddress.getHeight(),PaneSize.width, PaneSize.height/6);
		TargetProtocolAddress.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[8]+" : "+values[8]);
			}
		});
		
	}


	public String isProtocol() {
		// TODO Auto-generated method stub
		return "ARP_RARP";
	}


	public void onPane() {
		// TODO Auto-generated method stub
		this.setVisible(true);
	}


	public void offPane() {
		// TODO Auto-generated method stub
		this.setVisible(false);
	}
	
}
